//
//  DEWRingBtnView.m
//  OtherDemo
//
//  Created by kangbinbin on 2018/7/28.
//  Copyright © 2018年 lianjie. All rights reserved.
//

#import "DEWRingBtnView.h"

@interface DEWRingBtnView ()



@end

@implementation DEWRingBtnView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        
    }
    return self;
}
-(void)buttonClick:(UIButton *)sender{
    if (sender.tag == 100) {
        if (self.opposeBtnBlock) {
            self.opposeBtnBlock(@"1");
        }
    }else{
        if (self.agreeBtnBlock) {
            self.agreeBtnBlock(@"1");
        }
    }

    NSLog(@"=========");
    
}
-(void)layoutSubviews{
    [super layoutSubviews];
//    _IsType = @"1";
    if ([_IsType isEqualToString:@"1"]) {
        
        UIButton *OpposeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        OpposeBtn.frame = CGRectMake(0, 35 / 2, 117, 35);
        [OpposeBtn setTitle:@"反对" forState:UIControlStateNormal];
        [OpposeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [OpposeBtn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        [OpposeBtn setBackgroundColor:UIColorFromRGB(0xFF7551)];
        OpposeBtn.tag = 100;
        OpposeBtn.layer.cornerRadius = 4;
        [self addSubview:OpposeBtn];
        
        UIButton *agreeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        agreeBtn.frame = CGRectMake(128, 35 / 2, 117, 35);
        [agreeBtn setTitle:@"支持" forState:UIControlStateNormal];
        [agreeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [agreeBtn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        [agreeBtn setBackgroundColor:UIColorFromRGB(0x76CC3A)];
        agreeBtn.layer.cornerRadius = 4;
        agreeBtn.tag = 101;
        [self addSubview:agreeBtn];
        
    }else{
        //反对
        UILabel *opposeL = [[UILabel alloc]init];
        opposeL.x = 0;
        opposeL.width = 27;
        opposeL.height = 19;
        //    opposeL.centerY = self.centerY;
        opposeL.y = (79- 27) / 2;
        opposeL.text = @"反对";
        opposeL.textColor = UIColorFromRGB(0xFF7551);
        opposeL.font = [UIFont systemFontOfSize:13];
        //    opposeL.layer.borderColor = UIColorFromRGB(0xFF7551).CGColor;
        //    opposeL.layer.borderWidth = 1;
        [self addSubview:opposeL];
        //反对图片
        UIImageView *opposeImgView = [[UIImageView alloc]init];
        opposeImgView.x = opposeL.right+ 2;
        opposeImgView.width = 10;
        opposeImgView.height = 7;
        opposeImgView.centerY = opposeL.centerY;
        opposeImgView.image = [UIImage imageNamed:@"支持对勾"];
        [self addSubview:opposeImgView];
        //同意view
        UIView *agreeView = [[UIView alloc]init];
        agreeView.x = opposeL.right + 15;
        //    agreeView.centerX = opposeImgView.centerX;
        agreeView.y = 30;
        agreeView.width = self.width - 45 * 2;
        agreeView.height = 10;
        agreeView.layer.cornerRadius = 5;
        agreeView.backgroundColor = UIColorFromRGB(0x76CC3A);
        [self addSubview:agreeView];
        
        //不同意view
        UIView *opposeView = [[UIView alloc]init];
        opposeView.x = opposeL.right + 15;
        //    opposeView.centerY = opposeImgView.centerY;
        opposeView.y = 30;
        opposeView.width = agreeView.width * _oNum;
        opposeView.height = 10;
        opposeView.layer.cornerRadius = 5;
        opposeView.backgroundColor = UIColorFromRGB(0xFF7551);
        [self addSubview:opposeView];
        
        //同意图片
        UIImageView *agreeImgView = [[UIImageView alloc]init];
        agreeImgView.x = agreeView.right+ 2;
        agreeImgView.width = 10;
        agreeImgView.height = 7;
        agreeImgView.centerY = opposeL.centerY;
        agreeImgView.image = [UIImage imageNamed:@"支持对勾"];
        [self addSubview:agreeImgView];
        //同意的Label
        UILabel *agreeL = [[UILabel alloc]init];
        agreeL.x = agreeImgView.right + 2;
        agreeL.width = 27;
        agreeL.height = 19;
        agreeL.centerY = opposeL.centerY;
        agreeL.text = @"同意";
        agreeL.textColor = UIColorFromRGB(0x76CC3A);
        agreeL.font = [UIFont systemFontOfSize:13];
        //    agreeL.layer.borderColor = UIColorFromRGB(0x76CC3A).CGColor;
        //    agreeL.layer.borderWidth = 1;
        [self addSubview:agreeL];
        //反对的数值
        UILabel *opposeNumL = [[UILabel alloc]init];
        opposeNumL.x = opposeView.x;
        opposeNumL.width = opposeView.width;
        opposeNumL.height = 17;
        opposeNumL.y = agreeView.y - 17;
        opposeNumL.text = [NSString stringWithFormat:@"%.0f%%%",_oNum * 100];
        opposeNumL.textColor = UIColorFromRGB(0x666666);
        opposeNumL.font = [UIFont systemFontOfSize:13];
        opposeNumL.textAlignment = NSTextAlignmentCenter;
        [self addSubview:opposeNumL];
        
        //同意的数值
        UILabel *agreeNumL = [[UILabel alloc]init];
        agreeNumL.x = opposeView.right;
        agreeNumL.width = agreeView.width - opposeView.width;
        agreeNumL.height = 17;
        agreeNumL.y = agreeView.y - 17;
        agreeNumL.text = [NSString stringWithFormat:@"%.0f%%%",100 - _oNum * 100];;
        agreeNumL.textColor = UIColorFromRGB(0x666666);
        agreeNumL.font = [UIFont systemFontOfSize:13];
        agreeNumL.textAlignment = NSTextAlignmentCenter;
        [self addSubview:agreeNumL];
    }
    
    
    
        
}

@end
